{% extends "base.html" %}
{% block title %}{% endblock %}
{% block content %}
<br>
<form class="layui-form" action="" id="cross_srh">
    <div class="proxy_srh">
        <div class="layui-inline">
            <div class="layui-inline">
                <label class="layui-form-label">project_name：</label>
            <div class="layui-input-inline">
                <select class="layui-select" name="project_name" id="project_name" lay-verify="" lay-search
                                lay-filter="project_name">

                            {% for d in projectAll %}
                                <option value={{d.id}}>{{d.project_name}}</option>
                            {% endfor %}
                </select>
            </div>
                <div class="layui-input-inline">
                    <label class="layui-form-label">param_name：</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="param_name" id="param_name" placeholder="请输入" style="width:212px">
                    </div>
                </div>

                <div class="layui-inline" style="left: 257px">
                    <button class="layui-btn" type="button" id="start" lay-submit lay-filter="start">查询</button>
                </div>
            </div>
        </div>

    </div>
</form>
<hr class="layui-bg-gray">
<button class="layui-btn  layui-btn-normal" id="add" type="button">
    <i class="layui-icon"></i> 创建参数
</button>

<script type="text/html" id="filemange_v1">
    <button type="button"  class="layui-btn layui-btn-xs layui-btn-danger" lay-event="update">更新</button>
    <button type="button" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="delNode">
    <i class="layui-icon">&#xe640;</i>
  </button>
</script>
<div class="layui-table-body" style="overflow:visible">
<table class="layui-hide" id="apiCaseParam" lay-filter="apiCaseParam"></table>
</div>
<script>
    layui.use(['table','code'], function(){
          var table = layui.table
          ,form = layui.form;
          var $= layui.jquery;
          var loading = layer.load();

          var  options = {
                elem:'#apiCaseParam',
                skin:"line",
                page:true,
                height: 'full-200',
                toolbar: true,
                url:'/case/api/params/srh?',
                limit:10,
                limits:[10,20,30],
                where:{
                    project_id : $('#project_name option:selected').val(),
                    param_name: $('#param_name').val()
                },
                response:{
                    statusName:'errorCode',
                    statusCode:'',
                    dataName:'data'
                },
                cols:[[
                       {type: 'numbers'}
                      ,{field: 'param_name', title: 'param_name',sort:true}
                      ,{field: 'param_type', title: 'param_type',sort:true, templet: function (d) {
                            if(d.param_type == "0"){
                                return "全局变量";
                            }else if(d.param_type == "1"){
                                return "GET请求";
                            }else if(d.param_type == "2"){
                                return "Response字符关联";
                            }else if(d.param_type == "3"){
                                return "Response对象取值";
                            }
                            return d.param_type

                       }}
                      ,{field: 'param_value', title: 'param_value',sort:true}
                      ,{field: 'last_time', title: 'last_time',sort:true}
                      ,{field: 'case_id', title: 'case_id',sort:true,width:1}
                      ,{field: 'leftStr', title: 'leftStr',sort:true,width:1}
                      ,{field: 'rightStr', title: 'rightStr',sort:true,width:1}
                      ,{field: 'indexStr', title: 'indexStr',sort:true,width:1}
                      ,{field: 'jsonObj', title: 'jsonObj',sort:true,width:1}
                      ,{field: 'id', title: 'id',sort:true,width:1}
                      ,{fixed: 'right', title:'', toolbar: '#filemange_v1',width:170}

                ]],
                id:'apiCaseParam',
                done:function(res,cur,count){
                    $("[data-field='case_id']").css('display','none');
                    $("[data-field='leftStr']").css('display','none');
                    $("[data-field='rightStr']").css('display','none');
                    $("[data-field='indexStr']").css('display','none');
                    $("[data-field='jsonObj']").css('display','none');
                    $("[data-field='id']").css('display','none');

                    layer.close(loading);
                }
              };
          var tableIns = table.render(options);

          table.on('row(apiCase)', function(obj){
                obj.tr.css("background","#eeeeee");
          });
          table.on('rowDouble(apiCase)', function(obj){
            msg = JSON.stringify(obj.data, null, 4);

            layer.open({
              title: obj.data.param_name + '_详细参数',
              area:['1055px','473px']
              ,content: '<pre>'+msg+'</pre>'
              ,closeBtn:1,
              shade: 0,
              shadeClose:true
            });

          });



          $('#add').on('click',function(){
                layui.data('test', {key: 'apiCaseParams',value: undefined});
                layer.open({
                            type:2,
                            content:"/api/case/params/manage?token={{token}}&openId={{openId}}",
                            area:['425px','527px'],
                            //offset: ['231px','307px'],
                            title:"创建变量",
                            closeBtn:1,
                            shade: 0,
                            shadeClose:true,
                            cancel: function(index, layero){
                                 $('#start').click();
                            }
                });
          });

          //点击查询
          $('#start').on('click',function(){
              var loading = layer.load();

              options = {
                elem:'#apiCaseParam',
                skin:"line",
                page:true,
                height: 'full-200',
                toolbar: true,
                url:'/case/api/params/srh?',
                limit:10,
                limits:[10,20,30],
                where:{
                    project_id : $('#project_name option:selected').val(),
                    param_name: $('#param_name').val()
                }
              }
              tableIns.reload(options);
              layer.close(loading);
          });

          table.on('tool(apiCaseParam)', function(obj){

                if(obj.event === 'update'){
                    layui.data('test', {key: 'apiCaseParams',value: obj.data});
                    layer.open({
                            type:2,
                            content:"/api/case/params/manage?token={{token}}&openId={{openId}}",
                            area:['425px','527px'],
                            //offset: ['231px','307px'],
                            title:"更新变量",
                            closeBtn:1,
                            shade: 0,
                            shadeClose:true,
                            cancel: function(index, layero){
                                 $('#start').click();
                            }
                     });
                }else if(obj.event ==="delNode"){
                    layer.confirm('真的删除行么?', function(index){
                        $.ajax({
                                        //发出请求
                                        type:"POST",
                                        url:"/case/api/params/del",
                                        contentType: 'application/json; charset=utf-8',
                                        dataType:"json",
                                        data:JSON.stringify({"id":obj.data.id}),
                                        success: function(result){
                                            obj.del();
                                            layer.close(index);
                                            layer.msg("删除成功!");

                                        }
                        });
                    });
                }
          });

          form.render();
          layer.close(loading);

    });
</script>
{% endblock %}